package com.chinatelecom.otms.circuitcheck.runnable;

import com.chinatelecom.otms.circuitcheck.entity.CheckCircuit;
import com.chinatelecom.otms.circuitcheck.service.CheckCircuitService;
import com.chinatelecom.otms.circuitcheck.util.Common;

public class CheckCircuitRunnable implements Runnable {
    private CheckCircuit checkCircuit;
    private CheckCircuitService checkDataService;
    private String is_snc_or_fdfr;
    private Integer count;
    private Integer total;

    public CheckCircuitRunnable(CheckCircuit checkCircuit, CheckCircuitService checkDataService, Integer count, Integer total, String is_snc_or_fdfr) {
        this.checkCircuit = checkCircuit;
        this.checkDataService = checkDataService;
        this.count = count;
        this.total = total;
        this.is_snc_or_fdfr = is_snc_or_fdfr;
    }

    @Override
    public void run() {
        try {

//            checkCircuit = checkDataService.getAllEquipments(checkCircuit);
//            checkCircuit = checkDataService.getAllPhysicalTerminationPointsWithoutFtps(checkCircuit);


            if(is_snc_or_fdfr.equals("snc")){
                checkCircuit = checkDataService.updateSncByInterface(checkCircuit);
                if(checkCircuit.getGetAllEquipmentsResult().equals("getSNC:SUCCESS")){
                    checkCircuit = checkDataService.updateRouteDescBySncRef(checkCircuit);
                    System.out.println("电路串接完成，电路SNC: " + checkCircuit.getSnc_id() + ", EMS_ID: " + checkCircuit.getEms_id()
                            + ", 串接结果: " + checkCircuit.getRoute_desc());
                }else{
                    System.out.println("获取SNC失败。。。。，电路SNC: " + checkCircuit.getSnc_id() + ", EMS_ID: " + checkCircuit.getEms_id()
                            + ", 串接结果: " + checkCircuit.getRoute_desc());
                }
                count ++;
                System.out.println("当前进度：" + count + ", 总数：" + total);
            }else if(is_snc_or_fdfr.equals("fdfr")){
                checkCircuit = checkDataService.getFDFR(checkCircuit);
                if(checkCircuit.getGetAllEquipmentsResult().equals("getFDFR:SUCCESS")){
                    checkCircuit = checkDataService.getFDFRRoute(checkCircuit);
                    System.out.println("FDFR ROUTE完成，FDFR_ID: " + checkCircuit.getSnc_id() + ", EMS_ID: " + checkCircuit.getEms_id()
                            + ", getRoute结果: " + checkCircuit.getGetAllEquipmentsResult());
                }else{
                    System.out.println("获取FDFR ROUT失败。。。。，FDFR_ID: " + checkCircuit.getSnc_id() + ", EMS_ID: " + checkCircuit.getEms_id()
                            + ", getRoute结果: " + checkCircuit.getGetAllEquipmentsResult());
                }
                count ++;
                System.out.println("当前进度：" + count + ", 总数：" + total);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Common.countDownLatch.countDown();
        }
    }
}
